home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Pair / Pair.C < prev    next >
C/C++ Source or Header  |  1992-06-29  |  3KB  |  121 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/Pair.h>
  14.  
  15. // CoolPair -- Empty constructor
  16. // Input:  None.
  17. // Output: None.
  18.  
  19. template<class T1, class T2> 
  20. CoolPair<T1,T2>::CoolPair<T1,T2> () {
  21.   if (this->compare_s == NULL)            // if no compare function
  22.     this->compare_s = &CoolPair<T1,T2>_is_data_equal; // default
  23. }
  24.  
  25.  
  26. // CoolPair (T1,T2) -- Constructor that initializes the first and second elements
  27. // Input:          Reference to first value, reference to second value
  28. // Output:         None.  
  29.  
  30. template<class T1, class T2> 
  31. CoolPair<T1,T2>::CoolPair<T1,T2> (const T1& first, const T2& second) {
  32.   this->firstd = first;
  33.   this->secondd = second;
  34.   if (this->compare_s == NULL)            // if no compare function
  35.     this->compare_s = &CoolPair<T1,T2>_is_data_equal; // default
  36. }
  37.  
  38.  
  39. // CoolPair (CoolPair) -- Constructor for reference to another pair
  40. // Input:         Reference to another pair
  41. // Output:        None.
  42.  
  43. template<class T1, class T2> 
  44. CoolPair<T1,T2>::CoolPair<T1,T2> (const CoolPair<T1,T2>& p) {
  45.   this->firstd = p.firstd;
  46.   this->secondd = p.secondd;
  47. }
  48.  
  49.  
  50. // ~CoolPair -- Destructor for pair does nothing
  51. // Input:         None.
  52. // Output:        None.
  53.  
  54. template<class T1, class T2> 
  55. CoolPair<T1,T2>::~CoolPair<T1,T2> () {}
  56.  
  57.  
  58.  
  59. // operator= -- Assigns this pair to another
  60. // Input:  Reference to another pair
  61. // Output: Reference to the copied pair
  62.  
  63. template<class T1, class T2> 
  64. CoolPair<T1,T2>& CoolPair<T1,T2>::operator= (const CoolPair<T1,T2>& p) {
  65.   this->firstd = p.firstd;
  66.   this->secondd = p.secondd;
  67.   return *this;
  68. }
  69.  
  70.  
  71. // operator<< -- Output a pair
  72. // Input:        Reference to an ostream, reference to a pair
  73. // Output:       Reference to the modified ostream
  74.  
  75. template<class T1, class T2> CoolPair {
  76. ostream& operator<< (ostream& os, const CoolPair<T1,T2>& p) {
  77.   os << "[" << p.firstd << " " << p.secondd << "] ";
  78.   return os;
  79. }}
  80.  
  81.  
  82. // is_data_equal -- Default data comparison function if user has not provided
  83. //                  another one. 
  84. // Input:           Two references to pairs
  85. // Output:          TRUE or FALSE
  86.  
  87. template<class T1, class T2> CoolPair {
  88. Boolean CoolPair<T1,T2>_is_data_equal (const CoolPair<T1,T2>& p1, 
  89.                        const CoolPair<T1,T2>& p2) {
  90.   return ((p1.firstd == p2.firstd) && (p1.secondd == p2.secondd));
  91. }}
  92.  
  93. // set_compare -- Specify the comparison function to be used in logical tests
  94. //                of the elements of pairs
  95. // Input:         Pointer to compare function
  96. // Output:        None
  97.  
  98. template<class T1, class T2> 
  99. void CoolPair<T1,T2>::set_compare (CoolPair<T1,T2>_Compare cf) {
  100.   if (cf == NULL)            // if no compare function
  101.     this->compare_s = &CoolPair<T1,T2>_is_data_equal; // default
  102.   else
  103.     this->compare_s = cf;
  104. }
  105.  
  106.  
  107. // print --  terse print function for CoolPair
  108. // Input:    reference to output stream
  109. // Output:   none
  110.  
  111. template<class T1, class T2>
  112. void CoolPair<T1,T2>::print (ostream& os) {
  113.   os << form("/* CoolPair %lx */", (long) this);
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.